import {getRequest, postRequest} from "@/utils/request.js";

export async function loadDanmuPool(videoId) {
    try {
        return await getRequest('/heaven-server/danmuku/load', {videoId: videoId});
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `请求失败-${e.message}`}
    }
}

/**
 *
 * @param videoId
 * @param danmuData
 * 弹幕数据格式:
   {
      text: '', // 弹幕文本
      time: 10, // 弹幕时间, 默认为当前播放器时间
      mode: 0, // 弹幕模式: 0: 滚动(默认)，1: 顶部，2: 底部
      color: '#FFFFFF', // 弹幕颜色，默认为白色
      border: false, // 弹幕是否有描边, 默认为 false
      style: {}, // 弹幕自定义样式, 默认为空对象
  }
 */
export async function sendDanmu(videoId, danmuData) {
    danmuData['videoId'] = videoId;
    danmuData['sendTime'] = new Date();
    try {
        return await postRequest('/heaven-server/danmuku/auth/send', danmuData);
    } catch (e) {
        console.log(e);
        return {code: -1, msg: `请求失败-${e.message}`}
    }
}